/**
* @FileName: ExceptionResolver.java
* @Package com.cta.platform.resolver
* @Description: 
* @author chenwenpeng
* @date 2013-6-4 下午03:23:19
* @version V1.0
*/
package com.cbank.platform.handler;

import java.lang.annotation.Annotation;

import javax.servlet.http.HttpServletRequest;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebArgumentResolver;
import org.springframework.web.context.request.NativeWebRequest;

import com.cbank.platform.annotation.RequestAttribute;

/**
 * @ClassName:
 * @Description: requestAttribute处理
 * @author chenwenpeng
 * @date 2016-11-15
 *
 */
public class RequestAttributeArgumentResolver implements WebArgumentResolver {

	public Object resolveArgument(MethodParameter param, NativeWebRequest request) {
		Annotation[] paramAnns = param.getParameterAnnotations();
		for (Annotation paramAnn : paramAnns) {
			if (RequestAttribute.class.isInstance(paramAnn)) {
				RequestAttribute reqAttr = (RequestAttribute) paramAnn;
				HttpServletRequest httprequest = (HttpServletRequest) request.getNativeRequest();
				Object result = httprequest.getAttribute(reqAttr.value());
				return result;
			}
		}
		return WebArgumentResolver.UNRESOLVED;
	}
}
